<template>
  <uni-nav-bar title="首页" color="#333" :border="false" statusBar></uni-nav-bar>
  <view class="package_sale space-between">
    <view class="center top">
      <image :src="userInfo.userInfor.avatar?userInfo.userInfor.avatar:avatar" mode=""></image>
      <view>{{userInfo.userInfor.name?userInfo.userInfor.name:'用户名'}}</view>
    </view>
    <uni-icons type="scan" size="30" @click="scanCode()"></uni-icons>
  </view>
  <!-- 工作状态 -->
  <Working></Working>
  <!-- 切换 -->
  <z-tabs ref="tabs" :list="list" :current="current" @change="tabsChange" inactive-color="#333" />
  <!-- 统计 -->
  <Statistics v-if="current===0||current===1" ref="count"></Statistics>
  <!-- 加注量 -->
  <Fill v-if="current===0" :fillList="information.informationMine"></Fill>
  <!-- 收益 -->
  <Income v-if="current===0" :income="information.informationMine"></Income>
  <!-- 新增车友 -->
  <NewFriend v-if="current===0" :newFriend="information.informationMine"></NewFriend>
  <!-- 排行榜 -->
  <PieChart v-if="current===1" :pieChart="information.informationGroup"></PieChart>
  <!-- 活动 -->
  <ActivityList v-if="current===2" :activityList="information.informationMovable">
  </ActivityList>
  <!-- 公告列表 -->
  <Notice v-if="current===3"></Notice>
  <!-- 未登录弹框 -->
  <Unlisted></Unlisted>
</template>

<script setup lang="ts">
  import { ref } from 'vue';
  import { avatar } from '@/utils/Static';
  import Working from '@c/index/working.vue';
  import Unlisted from '@c/common/unlisted.vue';
  import Statistics from '@c/index/statistics.vue';
  import ActivityList from '@c/list/activityList.vue';
  import Fill from '@c/index/fill.vue';
  import Income from '@c/index/income.vue';
  import NewFriend from '@c/index/newFriend.vue';
  import { onPullDownRefresh } from '@dcloudio/uni-app';
  import PieChart from '@c/index/pieChart.vue';
  import Notice from '@c/index/notice.vue';
  import { useUserStore } from '@/stores/user';
  import { DataStore } from '@/stores/data';
  const userInfo = useUserStore();
  const information = DataStore()
  const list = [{ name: '个人' }, { name: '团队' }, { name: '活动' }, { name: '公告' }]
  const current = ref(0)
  const tabs = ref(null)
  const count = ref(null)
  userInfo.getUserInfo();
  information.informationMY('today')
  information.informationTeam('today')
  information.informationActive()
  onPullDownRefresh(() => {
    userInfo.getUserInfo();
    information.informationMY('today')
    information.informationTeam('today')
    information.informationActive()
    uni.stopPullDownRefresh();
  })

  //tabs通知swiper切换
  function tabsChange(index : number) {
    current.value = index;
    if (index === 0 || index === 1 && count.value) {
      count.value.blockedOut(index)
    }
  }
  function scanCode() {
    uni.scanCode({
      success: function (res) {
        console.log('条码类型：' + res.scanType);
        console.log('条码内容：' + res.result);
      }
    });
  }
</script>
<style scoped lang="less">
  .top {
    image {
      width: 80rpx;
      height: 80rpx;
      border-radius: 50%;
      margin-right: 15rpx;
    }
  }
</style>